qui(
    function (require, exports, module) {
        VODCom.NewsHighlight = (function () {
            var _config = null;
            var lastOption = null;
            var defaults = {
                st: 0,
                et: 0,
                pic: 0,
                color: 'cfff',
                bgColor: 'c09f',
                removeColor: ''
            };

            function setHighLight(options) {
                quickClearBgColor();
                $('.p-l').remove();
                $('.p-r').remove();
                $('.p-middle').remove();
                reSetOpacity();
                if (options != null) {
                    lastOption = $.extend({}, defaults, options);
                    addBackgroundColor(lastOption)
                    addInOutMark(lastOption);
                } else {
                    lastOption = null;
                }
            }

            function addInOutMark(options) {
                var bigMark = '';
                if ($("#changeBigPic").hasClass('btn-primary')) {
                    bigMark = 'in-out-mark-b';
                }
                var showIdTitle = options.id == -999 ? " " : options.id;
                var str = "";
                if (options.hasOwnProperty("st")) {
                    str = '<div onclick="VODCom.NewsHighlight.clearPoint(this,1)" class="absolute in-out-mark-s ' + bigMark + ' p-l p-l-' + options.id + '">' + showIdTitle + '<br>入<br>点</div>';
                    $('#img-' + options.st).after(str);
                    $('#img-' + options.st).parent().find(".p-r").remove();
                }
                if (options.hasOwnProperty("et")) {
                    str = '<div onclick="VODCom.NewsHighlight.clearPoint(this,2)" class="absolute in-out-mark-s ' + bigMark + ' p-r p-r-' + options.id + '">' + showIdTitle + '<br>出<br>点</div>';
                    $('#img-' + options.et).after(str);

                    $('#img-' + options.et).parent().find(".p-l").remove();
                }
                VODCom.NewsHighlight.reSetOpacity();
                if (options.hasOwnProperty("pic")) {
                    str = '<div onclick="$(this).remove()" class="absolute in-out-mark-s ' + bigMark + ' p-middle p-middle-' + options.id + '">' + showIdTitle + '<br>封<br>面</div>';
                    $('#img-' + options.pic).after(str);
                }
            }

            function addInOutMaskMark(options) {
                var bigMark = '';
                if ($("#changeBigPic").hasClass('btn-primary')) {
                    bigMark = 'in-out-mark-b';
                }
                var showIdTitle = options.maskIndex < 0 ? " " : options.maskIndex;
                var str = "";
                if (options.hasOwnProperty("maskST")) {
                    $('#img-' + options.maskST).parent().find(".mask-r").remove();
                }
                if (options.hasOwnProperty("maskET")) {
                    $('#img-' + options.maskET).parent().find(".mask-l").remove();
                }
                if (options.hasOwnProperty("maskST")) {
                    str = '<div onclick="$(this).remove()" class="absolute in-out-mark-s ' + bigMark + ' mask-l mask-l-' + options.maskIndex + '">' + showIdTitle + '<br>遮<br>头</div>';
                    $('#img-' + options.maskST).after(str);
                }

                if (options.hasOwnProperty("maskET")) {
                    str = '<div onclick="$(this).remove()" class="absolute in-out-mark-s ' + bigMark + ' mask-r mask-r-' + options.maskIndex + '">' + showIdTitle + '<br>遮<br>尾</div>';
                    $('#img-' + options.maskET).after(str);
                }
            }

            function setMaskStart(value) {
                var entity = _config.MaskManager.getSelectMaskEntity();
                if (entity == null) {
                    _config.Plugin.tips("error", _config.Config.REMIND_MSG_INFO.NOT_BIND_MASK);
                    return;
                }
                var newstart = value == null ? validCheck() : value;
                $('.mask-l-' + entity.index).remove();
                addInOutMaskMark({maskST: newstart, maskIndex: entity.index, maskET: entity.eTime});
                _config.Util.updateGridMaskEntityRow({index: entity.index, sTime: newstart, eTime: entity.eTime  })
            }

            function setMaskEnd(value) {
                var entity = _config.MaskManager.getSelectMaskEntity();
                if (entity == null) {
                    _config.Plugin.tips("error", _config.Config.REMIND_MSG_INFO.NOT_BIND_MASK);
                    return;
                }
                var newEnd = value == null ? validCheck() : value;
                $('.mask-r-' + entity.index).remove();
                addInOutMaskMark({maskET: newEnd, maskIndex: entity.index, maskST: entity.sTime});
                _config.Util.updateGridMaskEntityRow({index: entity.index, eTime: newEnd, sTime: entity.sTime  })
            }

            function clearMaskMark() {
                $('.mask-l').remove();
                $('.mask-r').remove();
            }

            function clearMaskSingleMark(index) {
                $('.mask-l-' + index).remove();
                $('.mask-r-' + index).remove();
            }

            function addBackgroundColor(options) {
                for (var i = options.st; i <= options.et; i++) {
                    if (!options.removeColor) {
                        $('#img-' + i).addClass(options.color).addClass(options.bgColor);
                    } else {
                        $('#img-' + i).removeClass(options.color).removeClass(options.bgColor);
                    }
                }
            }

            function quickClearBgColor() {
                $('.c09f').removeClass("c09f");
                $('.cfff').removeClass("cfff");
            }

            function validCheck() {
                return parseInt($(".red").parent().find(".pid").html());
            }

            function setNewStart(value) {
                quickClearBgColor();
                var newstart = value == null ? validCheck() : value;
                var maxValue = parseInt($('#picNum').text()) - 1;
                if (newstart != null) {
                    if (newstart >= maxValue) {
                        console.log("wrong  st " + newstart)
                        return;
                    }
                    var updateObj = {id: -999, sTime: newstart};
                    _config.AccurateFrame.updateAccurateFrame({head: '', headSetted: false})
                    _config.Util.updateCForm(updateObj)
                    $('.p-l').remove();
                    addInOutMark({ id: -999, st: newstart})
                }
            }

            function setNewEnd(value) {
                quickClearBgColor();
                var newEnd = value == null ? validCheck() : value;
                if (newEnd != null) {
                    if (newEnd == 0) {
                        console.log("wrong et " + newEnd);
                        return;
                    }
                    var updateObj = {id: -999, eTime: newEnd};
                    _config.AccurateFrame.updateAccurateFrame({end: '', endSetted: false})
                    _config.Util.updateCForm(updateObj)
                    $('.p-r').remove();
                    addInOutMark({ id: -999, et: newEnd})
                }
            }


            function setNewImage(value) {
                quickClearBgColor();
                var image = value == null ? validCheck() : value;
                if (image != null) {
                    var updateObj = { id: -999, pic: image};
                    _config.Util.updateCForm(updateObj);
                    $('.p-middle').remove();
                    addInOutMark({ id: -999, pic: image})
                }
            }

            function getLastOption() {
                if (lastOption == null) {
                    return null;
                }
                return $.extend({}, lastOption);
            }

            function setNewOption(options) {
                switch (options.key) {
                    case "st":
                        setNewStart(options.value);
                        break;
                    case "et":
                        setNewEnd(options.value);
                        break;
                    case "pic":
                        setNewImage(options.value)
                        break;
                }
            }

            function clearPoint(element) {
                $(element).remove();
                reSetOpacity();
            }

            function reSetOpacity() {
//                $("img.fragment-img").parent().css({
//                    opacity: 1
//                })
//                var st = $(".p-l").parent().find(".pid").text();
//                var et = $(".p-r").parent().find(".pid").text();
//                if (st == "" && et == "") {
//                    return;
//                } else {
//                    if (st != "") {
//                        $("img.fragment-img:lt(" + st + ")").parent().css({
//                            opacity: 0.3
//                        })
//                    }
//                    if (et != "") {
//                        $("img.fragment-img:gt(" + et + ")").parent().css({
//                            opacity: 0.3
//                        })
//                    }
//                }
            }

            function triggerAddNewImage() {
//                var et = $(".p-r").parent().find(".pid").text();
//                if (et != "") {
//                    $("img.fragment-img:gt(" + et + ")").parent().css({
//                        opacity: 0.3
//                    })
//                }
            }

            function bindConfig(newConfig){
                _config = newConfig;
            }

            return {
                bindConfig:bindConfig,
                setHighLight: setHighLight,
                setNewStart: setNewStart,
                setNewEnd: setNewEnd,
                setNewImage: setNewImage,
                getLastOption: getLastOption,
                setNewOption: setNewOption,
                quickClearBgColor: quickClearBgColor,
                addInOutMaskMark: addInOutMaskMark,
                setMaskStart: setMaskStart,
                setMaskEnd: setMaskEnd,
                clearMaskMark: clearMaskMark,
                clearMaskSingleMark: clearMaskSingleMark,
                clearPoint: clearPoint,
                reSetOpacity: reSetOpacity,
                triggerAddNewImage: triggerAddNewImage
            }

        })()
    }
);